#include<stdio.h>
int main()
{
    int year = 0;
    int mou;

    while (scanf("%d %d", &year, &mou) == 2)
    {
        int mou_day[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
        int run(int);
        if (run(year) == 1)
            mou_day[2] = 29;
        printf("%d\n", mou_day[mou]);
    }
    return 0;
}
int run(int year)
{
    if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
    {
        return 1;
    }
    return 0;
}